package com.dz.common.web;

import java.io.IOException;
import java.nio.charset.Charset;

import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;

import springfox.documentation.spring.web.json.Json;

import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter4;

public class JsonHttpMessageConverter extends FastJsonHttpMessageConverter4 {

	public Charset getDefaultCharset() {
		return Charset.forName("utf-8");
	}

	protected MediaType getDefaultContentType(Object t) throws IOException {
		return MediaType.APPLICATION_JSON_UTF8;
	}

	@Override
	protected void addDefaultHeaders(HttpHeaders headers, Object t, MediaType contentType) throws IOException {
		super.addDefaultHeaders(headers, t, contentType);
		headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
	}

	@Override
	protected boolean supports(Class<?> paramClass) {
		if(paramClass==Json.class){
			return false;
		}
		return super.supports(paramClass);
	}
}